#include "timer.h"
#include "debug_frmwrk.h"

#define UARTx       LPC_UART0

// this is timer library example
// setting to work all 4 timers with exponential differences

// functions that are executed on each interrupt of different timers
void s1(void)
{
    UARTPuts(UARTx, "This is interrupt No0 calling\n\r");
    return;
}

void s2(void)
{
    UARTPuts(UARTx, "This is interrupt No1 calling\n\r");
    return;
}

void s3(void)
{
    UARTPuts(UARTx, "This is interrupt No2 calling\n\r");
    return;
}

void s4(void)
{
    UARTPuts(UARTx, "This is interrupt No3 calling\n\r");
    return;
}

/* Main entry ------------------------------------------------------------- */
void main(void)
{
    // init debug
    debug_frmwrk_init();
    // init timer library
    init_timer();
    // array to store (unique)references to timers*
    // if deinit and then init back a timer, the reference is not the same!
    uint32_t arr[4] = {0, 0, 0, 0};
    // set timer scaling
    uint32_t prescale = 100, match = 5000;
    // enable all timers
    arr[0] = enable_timer(prescale * 1, match, s1);
    arr[1] = enable_timer(prescale * 2, match, s2);
    arr[2] = enable_timer(prescale * 4, match, s3);
    arr[3] = enable_timer(prescale * 8, match, s4);
    
    // do some stuff
    UARTPuts(UARTx, "Init Done. Test go!\n\r");
    uint32_t tick = 0xFFFFFFF;
    while (tick--);
    
    // finilize
    disable_timer(arr[0]);
    disable_timer(arr[1]);
    disable_timer(arr[2]);
    disable_timer(arr[3]);
    deinit_timer();
    return;
}
